package com.gitee.huxing.algorithmic.daily;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description: 巫师力量的总和
 * @ProjectName: algorithmic-pactice
 * @Package: TotalStrength
 * @ClassName: TotalStrength
 * @Author: huxingmale
 * @DateTime: 2022-05-22 11:01
 */
public class TotalStrength {

    public static void main(String[] args) {
        int[] strength = {5, 4, 6};
        new TotalStrength().totalStrength(strength);
    }
    public int totalStrength(int[] strength) {
        // 先统计当前数组所有的排列组合情况
        List<List<Integer>> res = permute(strength);
        res.forEach(System.out::println);
        long total = 0;
        for (List<Integer> power : res){
            int min = Integer.MAX_VALUE, sum = 0;
            for (int i = 0; i < power.size(); i++){
                min = Math.min(power.get(i), min);
                sum += power.get(i);
            }
            total += (long)min * (long)sum;
            System.out.println("total = " + total);
        }
        return (int)(total % ((10 << 9) + 7));
    }

    // 计算所有的排列组合情况
    // 计算所有的排列组合情况
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> res = new ArrayList<List<Integer>>();
        int n = nums.length;
        for (int left = 0; left < n; left++){
            int right = left + 1;
            while (right <= n){
                List<Integer> level = new ArrayList<Integer>();
                for (int i = left; i < right; i++){
                    level.add(nums[i]);
                }
                res.add(level);
                right++;
            }
        }
        return res;
    }
}
